package org.idea.qiyu.framework.apm.agent.collector.dao;

import org.idea.qiyu.common.dto.AgentCollectorDataDTO;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author linhao
 * @Date created in 7:22 下午 2021/9/9
 */
@Repository
public class IAgentCollectorDao {

    public static Map<String, Object> cache = new HashMap<>();

    public Map<String, Object> getAllData() {
        return cache;
    }

    public boolean insertCollectorData(AgentCollectorDataDTO agentCollectorDataDTO) {
        AgentCollectorDataDTO currentRecord = (AgentCollectorDataDTO) cache.get(agentCollectorDataDTO.getHeadTraceId());
        if (currentRecord != null) {
            currentRecord.getTraceIdMap().addAll(agentCollectorDataDTO.getTraceIdMap());
        } else {
            currentRecord = agentCollectorDataDTO;
        }
        cache.put(agentCollectorDataDTO.getHeadTraceId(), currentRecord);
        return true;
    }
}
